﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MetaSharp.Transformation
{
    [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
    public class TransformerAttribute : Attribute
    {
        public string Extension { get; private set; }
        public Type TransformerType { get; private set; }

        public TransformerAttribute(string extension, Type type)
        {
            if (extension == null)
                throw new ArgumentNullException("extension");
            if (type == null)
                throw new ArgumentNullException("type");

            if (!typeof(ITransformer).IsAssignableFrom(type))
                throw new ArgumentException("type must implement MetaSharp.Transformation.ITransformer.");

            extension = extension
                .Trim()
                .ToLowerInvariant();

            if (extension == string.Empty)
                throw new ArgumentException("Extension must not be empty");

            if (!extension.StartsWith("."))
                extension = "." + extension;

            this.Extension = extension;
            this.TransformerType = type;
        }
    }
}
